import os.path
import jieba
import wordcloud


def get_word_cloud_pic(filename: str, color="#000"):
    with open(filename, "rt", encoding="utf-8") as file:
        t = file.read()
        file.close()
    ls = jieba.lcut(t)
    res = []
    for word in ls:
        if len(word) > 1:
            res.append(word)
    txt = " ".join(res)
    w = wordcloud.WordCloud(width=1000, font_path="msyh.ttc", height=700, background_color=color)
    w.generate(txt)
    w.to_file(os.path.splitext(filename)[0] + ".png")


get_word_cloud_pic("新时代中国特色社会主义.txt")
get_word_cloud_pic("关于实施乡村振兴战略的意见.txt")
